// util 文件
var aes = require('./aes.js');
var utilMd5 = require('./md5.js');

function encrypt(data) {
    var srcs = aes.CryptoJS.enc.Utf8.parse(data);
    var encrypted = aes.CryptoJS.AES.encrypt(srcs, aeskey, { iv: aesiv, mode: aes.CryptoJS.mode.CBC, padding: aes.CryptoJS.pad.Pkcs7 });
    return encrypted.toString();
}
function decrypt(data,timestamp) {
    const Md5Str = utilMd5.hexMD5('platform=website' + timestamp);
    const aeskey = aes.CryptoJS.enc.Utf8.parse(Md5Str.substring(0, 16));
    const aesiv = aes.CryptoJS.enc.Utf8.parse(Md5Str.substring(Md5Str.length - 16, Md5Str.length));
    var decrypt = aes.CryptoJS.AES.decrypt(data, aeskey, { iv: aesiv, mode: aes.CryptoJS.mode.CBC, padding: aes.CryptoJS.pad.Pkcs7 });
    var decryptedStr = decrypt.toString(aes.CryptoJS.enc.Utf8);
    return decryptedStr.toString();
}
module.exports = {
    encrypt: encrypt,
    decrypt: decrypt
}
